package com.pet.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pet.common.controller.AbstractController;
import com.pet.model.common.dtos.ResponseResult;
import com.pet.model.common.enums.AppHttpCodeEnum;
import com.pet.model.user.pojos.ApUser;
import com.pet.model.user.pojos.ApUserArticle;
import com.pet.user.service.ApUserArticleService;
import com.pet.user.service.ApUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * APP用户信息表 控制器</p>
 */
@RestController
@RequestMapping("/api/v1/apUserArticle")
public class ApUserArticleController {

    private ApUserArticleService apUserArticleService;

    //注入
    @Autowired
    public ApUserArticleController(ApUserArticleService apUserArticleService) {
        this.apUserArticleService = apUserArticleService;
    }

    @PostMapping("/save")
    public ResponseResult<ApUserArticle> save(@RequestBody ApUserArticle record) {
        apUserArticleService.save(record);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    //更新数据
    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody ApUserArticle record) {
        LambdaQueryWrapper<ApUserArticle> wrapper = Wrappers.<ApUserArticle>lambdaQuery()
                .eq(ApUserArticle::getUserId, record.getUserId()).eq(ApUserArticle::getArticleId, record.getArticleId());
        apUserArticleService.remove(wrapper);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

}